//this class manages an array of contact objects.

import java.io.*;
import java.util.Scanner;

//one object of this class represents the Contact List as a whole
public class ContactList implements Serializable {

	// this is an array of the type contact
	private  int counter;
	private final int MAX_COUNTER = 10;
	private Contact[] contactArray;
	private static Contact c;
	private static int menuNum;
	private static Scanner s;
	// Constructor
	public ContactList() 
	{
		counter = 0;
		contactArray = new Contact[MAX_COUNTER];
		c = new Contact();
		menuNum = 0;
		s = new Scanner(System.in);
	}
	
	public void startContactList()
	{
		menu();
	}
	
	//adds element to array every time it is executed to allow for enough room in array W.W
	public void addElementToContactArray() 
	{
	//	contactArray[0] = c.readContact();
	}

	// this method will search by Last name and return them to console
	public void searchLastName(String lastName) 
	{
		
	}

	// this method will search by E-mail and return them to console
	public void searchEmail() 
	{
		
	}

	// this method will search by zipcode and return them to console
	public void searchZipcode() 
	{
		
	}

	// this method will sort the Contact List by last name, will also print in
	// the said order
	public void sortLastName() 
	{
		
	}

	// this method will print all of the contacts
	public void print() 
	{
		
	}
	// This method saves the contact to the list.
	public void saveContactToArray()
	{
		FileOutputStream outFile;
		ObjectOutputStream outObject;
		try
		{ outFile = new FileOutputStream ("data");
		outObject = new ObjectOutputStream(outFile);
		outObject.writeObject(c);
		outFile.close();
		outObject.close();
		} catch (IOException ioe)
		{ System.out.println ("Error writing objects to the file: "+ ioe.getMessage());

		}
	}
	
	// This method is opens a menu
	private static void menu()
	{
		while (true) {
			System.out.print("Main Menu\n\n");
			System.out.print("1. Add a new Contact.\n");
			System.out.print("2. Print out Contact List.\n");
			System.out.print("3. Search by last Name.\n");
			System.out.print("4. Exit program.\n\n");
			System.out.print("What would you like to do? ");
			menuNum = s.nextInt();
			switch (menuNum) 
			{
				case 1:	// Add a new Contact
					System.out.print("\n\nNew Contact\n\n");
					c.readContact();
					break;
				case 2: // print out Contacts
					break;
				case 3: // search by last name
					break;
				case 4: // exits the program
					System.out.print("Program will now exit. Good Bye!");
					return;
				default: // any other number
					break;
			}
		}
	}
}